/*
 * @Author: your name
 * @Date: 2021-12-23 14:21:56
 * @LastEditTime: 2021-12-29 11:50:23
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \my\src\index.js
 */
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import reportWebVitals from './reportWebVitals'
import routes from './route/index'
import {HashRouter, Routes, Route, Navigate} from 'react-router-dom'

ReactDOM.render(
    <HashRouter>
        <Routes>
            {routes.map(item => {
                if (item.children) {
                    return (
                        <Route key={item.path} path={item.path} element={<item.component/>}>
                            {item.children
                                ? item.children.map(item => (
                                    <Route
                                        key={item.path}
                                        path={item.path}
                                        element={<item.component/>}/>
                                ))
                                : null}
                        </Route>
                    )
                }
                return (
                    <Route
                        key={item.path}
                        path={item.path}
                        element={
                            item.path === '/' ? (
                                <Navigate to='/login'></Navigate>
                            ) : (
                                <item.component/>
                            )
                        }/>
                )
            })}
        </Routes>
    </HashRouter>,
    document.getElementById('root')
)

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals()
